CREATE TABLE [dbo].[ReceiptMain]
(
[ReceiptKey] [uniqueidentifier] NOT NULL,
[ReceiptTypeKey] [uniqueidentifier] NOT NULL,
[IsNumberAutoGenerated] [bit] NOT NULL,
[ReceiptNumber] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[IssuedOn] [datetime] NULL,
[Notes] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[UpdatedOn] [datetime] NOT NULL,
[AccessKey] [uniqueidentifier] NOT NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[SystemEntityKey] [uniqueidentifier] NOT NULL,
[IssuedToContactKey] [uniqueidentifier] NOT NULL,
[MarkedForDeleteOn] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [PK_ReceiptMain] PRIMARY KEY CLUSTERED ([ReceiptKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [AK_Receipt_ReceiptNumber] UNIQUE NONCLUSTERED ([ReceiptNumber]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ReceiptMain_AccessKey] ON [dbo].[ReceiptMain] ([AccessKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ReceiptMain_CreatedByUserKey] ON [dbo].[ReceiptMain] ([CreatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ReceiptMain_IssuedToContactKey] ON [dbo].[ReceiptMain] ([IssuedToContactKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ReceiptMain_ReceiptTypeKey] ON [dbo].[ReceiptMain] ([ReceiptTypeKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ReceiptMain_SystemEntityKey] ON [dbo].[ReceiptMain] ([SystemEntityKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_ReceiptMain_UpdatedByUserKey] ON [dbo].[ReceiptMain] ([UpdatedByUserKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [FK_Receipt_AccessMain] FOREIGN KEY ([AccessKey]) REFERENCES [dbo].[AccessMain] ([AccessKey])
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [FK_Receipt_ContactMain_IssuedTo] FOREIGN KEY ([IssuedToContactKey]) REFERENCES [dbo].[ContactMain] ([ContactKey])
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [FK_Receipt_ReceiptTypeRef] FOREIGN KEY ([ReceiptTypeKey]) REFERENCES [dbo].[ReceiptTypeRef] ([ReceiptTypeKey])
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [FK_Receipt_SystemEntity] FOREIGN KEY ([SystemEntityKey]) REFERENCES [dbo].[SystemEntity] ([SystemEntityKey])
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [FK_ReceiptMain_UniformRegistry] FOREIGN KEY ([ReceiptKey]) REFERENCES [dbo].[UniformRegistry] ([UniformKey])
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [FK_ReceiptMain_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[ReceiptMain] ADD CONSTRAINT [FK_ReceiptMain_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO